package com.cyy.snakebar;

import android.os.Bundle;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @InjectView(R.id.btn_snakebar)
    Button btnSnakebar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.inject(this);

    }

    @OnClick(R.id.btn_snakebar)
    public void onClick() {
        Snackbar.make(btnSnakebar,"你好",Snackbar.LENGTH_SHORT).show();

        Snackbar.make(btnSnakebar,"你好",Snackbar.LENGTH_SHORT)
                .setAction("action", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this, "点击的action把", Toast.LENGTH_SHORT).show();
                    }
                }).show();

        //修改Action的样式
       /* Snackbar snackbar = Snackbar.make(btnSnakebar,"hello",Snackbar.LENGTH_SHORT);
        //设置背景颜色
        snackbar.getView().setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        //设置消息的颜色
        TextView tv = (TextView) snackbar.getView().findViewById(R.id.snackbar_text);
        tv.setTextColor(getResources().getColor(R.color.colorPrimary));
        snackbar.setAction("action", new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
        ColoredSnackbar.warning(snackbar).show();*/

        //封装后的调用
        Snackbar snackbar1 = Snackbar.make(btnSnakebar,"hello snackbar",Snackbar.LENGTH_SHORT)
                .setAction("dosth", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
        }

    /**
     * 设置背景颜色
     */
    public static void setSnackbarMessagerTextColor(Snackbar snackbar,int color){
        View view = snackbar.getView();
        ((TextView)view.findViewById(R.id.btn_snakebar)).setTextColor(color);
    }
}
